<script lang='ts' setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import DictioanryTypeForm from './component/dictionary-type-form.vue'
import { redirectPath } from '/@/utils/router-kit';
import { DictionaryTypeListUrl, DictionaryTypeEditUrl } from '/@/views/org/mapping.json'
import dictionaryList from '/@/views/org/dictionary/component/dictionary-list.vue'
const router = useRouter();
const DictionaryTypeFormRef = ref();
const DictionaryListRef = ref();
const DictionaryTypeFormState = reactive({
    codeItemId: router.currentRoute.value.params.id as string,
    onBackClick: () => router.push({ path: DictionaryTypeListUrl }),
    saveForm: () => DictionaryTypeFormRef.value.save(),
    /**质量验收卡新增成功 跳转页面 */
    onAddFormSuccess: (formData: any) => {
        redirectPath(DictionaryTypeEditUrl + formData.codeItemId)
    }
})
</script>
<template>
    <jxtech-basic-header breadcrumb-mapping-url="/org/dictionary-type/index">
        <template #extra>
            <jxtech-save-button @click="DictionaryTypeFormState.saveForm"></jxtech-save-button>
            <jxtech-back-button @click="DictionaryTypeFormState.onBackClick"></jxtech-back-button>
        </template>
    </jxtech-basic-header>
    <el-card>
        <template #header>
            <div class="card-header">
                <span>数据字典类型</span>
            </div>
        </template>
        <dictioanry-type-form
            ref="DictionaryTypeFormRef"
            :code-item-id="DictionaryTypeFormState.codeItemId"
            @add-success="DictionaryTypeFormState.onAddFormSuccess"
        ></dictioanry-type-form>
    </el-card>

    <div class="mt10">
        <dictionary-list
            ref="DictionaryListRef"
            v-if="DictionaryTypeFormState.codeItemId"
            :codeItemId="DictionaryTypeFormState.codeItemId"
        ></dictionary-list>
    </div>
</template>